\pard\tx3120\tx3620\tx4120\fs28\li2620 The File class can be used to open a file, read information from it, write information to it, and move around within it. These facilities are, however, generic and not very rich in features. Therefore, most commonly, specialized classes will be subclassed from it.\
\fs16 \
\fs28 After allocating a File object, one can ask it to open a particular file in the file system (this initalizes the object). Since a File object can work with a single file, all messages directed at it will affect the file it has opened. If asked to open a second file while it has one opened, the File object will return an error. Closing the File will free the object.\
\fs16 \
\fs28 An open file in a File object has a current position, which is where any reading or writing can occurr. Reading or writing can occur in byte sized, or arbitrarily sized chunks. One can move the current position forward or backward by a specified number of bytes, or to an absolute position in the file. Writing at the end of the file will increase the file's size. All these methods that manipultate the file's contents return ErrorInfo objects when errors occurr.\
\fs16 \
\fs28 One can also obtain certain information about the File, including the full pathname, just the file name, or just the basename of the file it has opened, and its total size.\
\fs16 \
\b\i\fs28 This is 'beta', in so far as all the things described here are not implemented, and nothing is set in stone.\
NOTE that methods return Reply objects, not plain-jane id's as suggested here!
\b0\i0 \
\
\fs16 \
\pard\tx7140\li2100 \
\
\fs28 INSTANCE VARIABLES\
\fs16 \
\pard\tx7140\tx10180\tx10680\i\fs28\fi-4540\li7140 Inherited from Object
\i0 Class isa;\
\fs16 \
\i\fs28 Declared in File
\i0 Cstring fileName;\
long int accessType;\
FILE* theFile;\
Integer state;\
\fs16 \
\fs28 fileName The full pathname of the file being opened\
\fs16 \
\fs28 accessType Indicates what kind of file access we are doing\
\fs16 \
\fs28 theFile The file that the object makes use of.\
\fs16 \
\fs28 state A flag indicating what 'state' the file is in.\
\pard\tx7140\fs16\li2100 \
\
\
\fs28 METHOD TYPES\
\fs16 \
\pard\tx7140\tx10180\tx10680\fs28\fi-4540\li7140 Creating/Initializing, and Freeing
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Returns the path to the file, without including the file name itself. Note that it does include the final / in the pathname (e.g.
\f4 /usr/djb/super.eps
\f0 returns
\f4 /usr/djb/
\f0 ). The string that is generated must be disposed by the caller.\
\fs16 \
\pard\tx7140\b\li2100 \
\fs28 getExtension\
\pard\f1\b0\fi-1020\li3620 -
\f0 (Cstring)
\b getExtension\
\fs16 \
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Like getFilename, but this returns only the extension of the file name Thus, the file
\f4 /usr/djb/super.eps
\f0 returns merely
\f4 eps
\f0 .The string that is generated must be disposed by the caller.\
\fs16 \
\pard\tx7140\b\li2100 \
\fs28 getFilename\
\pard\f1\b0\fi-1020\li3620 -
\f0 (Cstring)
\b getFilename\
\fs16 \
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Returns a new string that contains the name of the file without its full path. E.g. if the full name is
\f4 /usr/djb/super.eps
\f0 , this returns just
\f4 super.eps
\f0 .The string that is generated must be disposed by the caller.\
\fs16 \
\pard\tx7140\b\li2100 \
\fs28 getPathname\
\pard\f1\b0\fi-1020\li3620 -
\f0 (Cstring)
\b getPathname\
\fs16 \
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Returns the full pathname to the file the object has open. This provides a new string which the recipient is responsible for disposing.\
\fs16 \
\pard\tx7140\b\li2100 \
\fs28 initFile:For:\
\pard\b0\fi-1020\li3620 - (id)
\b initFile:
\b0 (const char *)
\i filename
\b\i0 For:
\b0 (long int)
\i operation
\b\i0 \
\fs16 \
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 This acts identically to openFile:For:, below, and is provided merely to remain compatabile with what NeXT says one should provide (init menthods that start with the characters `init').\
\pard\tx7140\fs16\li2100 \
\b \
\fs28 moveTo:\
\pard\f1\b0\fi-1020\li3620 -
\f0 (id)
\b moveTo:
\b0 (FilePos)
\i byteLoc
\b\i0 \
\fs16 \
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Moves to the specified location in the file. If the
\i byteLoc
\i0 is out of range, an error is returned. If the file access method is FILE_APPEND, then this method will always return an error. If one tries to move beyond the end of a file, and error is generated (note that because FilePos is an unsigned quantity, one can not move past the beginning).\
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Creates a new File object, opening the file
\i filename
\i0 , if possible, for the specified operation. The
\i operation
\i0 can be one of FILE_READ, FILE_WRITE, FILE_READWRITE and FILE_APPEND. In all cases save FileAPPEND, the file is opened with the current position at the beginning of the file. In the case of FileAPPEND, it is at the end of the file.\
\i0 parameter. This, then, simply serves as a more common case wrapper around the preceeding method.\
\pard\tx7140\fs16\li2100 \
\b \
\fs28 readByte:\
\pard\f1\b0\fi-1020\li3620 -
\f0 (id)
\b readByte:
\b0 (byte*)
\i theByte
\b\i0 \
\fs16 \
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Reads a byte from the file, and returns it in theByte. If an error occurrs, including detection of EOF and reads during FILE_WRITE or FILE_APPEND, an error is returned.\
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 This reads up to
\i numBytes
\i0 into
\i buffer
\i0 from the file. If
\i buffer
\i0 is not of the proper size, the results are unpredictable. If any errors are encountered while reading, no further reading is done, and an error is returned. In all cases, the number of bytes actually read is returned in
\i bytesFound.
\i0 \
\fs16 \
\pard\tx7140\b\li2100 \
\fs28 writeByte:\
\pard\f1\b0\fi-1020\li3620 -
\f0 (id)
\b writeByte:
\b0 (byte)
\i theByte
\b\i0 \
\fs16 \
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 writes a byte to the file at the current position, and advances the position one byte. If an error occurs, including writing during FILE_READ, an error is returned.\
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 This writes up to
\i numBytes
\i0 from
\i buffer
\i0 into the file. If
\i buffer
\i0 is not of the proper size, the results are unpredictable. If any errors are encountered while writing, no further writing is done, and an error is returned. In all cases, the number of bytes actually written is returned in
\i bytesWrote.
\i0 \
\fs16 \
\pard\tx7140\b\li2100 \
\b0 \
\fs28 BUGS AND PROBLEMS\
\fs16 \
\pard\tx3120\tx3620\tx4120\fs28\li2620 I suspect a lot of this will break when things other than plain old files are added.\
there should probably be a free method corresponding to the close.\
There should be a FILE_MODIFY and a FILE_READMODIFY. These are the same as write, except that write creates or clears a file to start with. Perhaps pick better terms overall. Maybe FILE_NEWWRITE, FILE_NEWREADWRITE, FILE_WRITE, FILE_READWRITE. ? That would not be backwared compatable. But this isn't 'final' anyway. Tough luck on the macpaint and macpict converters! =) Also, the error diagnostics from the open routine should reflect error codes more accurately (tried to open, but it wasn't there!)\
\fs16 \
\pard\tx7140\li2100 \
\
\fs28 ENHANCEMENT IDEAS\
\fs16 \
\pard\tx3120\tx3620\tx4120\fs28\li2620 Add support for other types of streams\
\fs16 \
\pard\tx7140\li2100 \
\
\fs28 CONSTANTS AND DEFINED TYPES\
\fs16 \
\pard\tx6480\tx7180\fs24\fi-3860\li6480 /* Types of ways to access a file */\
#define FILE_READ 0\
#define FILE_WRITE 1\
#define FILE_READWRITE 2\
#define FILE_APPEND 3\
\
FilePos An unsigned number for specifying a byte position in a file.\
FilePosDelta An unsigned number for specifying a change in position in a file.\
Revision 1.2 92/04/05 22:52:03 deathReflects some of the miscelaneous revisions that have taken place. Last version of version 1.Revision 1.1 92/03/29 12:19:01 deathInitial revision
\pard\tx3120\tx3620\tx4120\fs28\li2620 $Log: File.rtf,v $Revision 1.2 92/04/05 22:52:03 deathReflects some of the miscelaneous revisions that have taken place. Last version of version 1.Revision 1.1 92/03/29 12:19:01 deathInitial revision
@
1.2
log
@Reflects some of the miscelaneous revisions that have taken place. Last version of version 1.
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Creates a new File object, opening the file
\i filename
\i0 , if possible, for the specified operation. The
\i operation
\i0 can be one of FILE_READ, FILE_WRITE, FILE_READWRITE and FILE_APPEND. In all cases save FileAPPEND, the file is opened with the current position at the beginning of the file. In the case of FileAPPEND, it is at the end of the file.\
\pard\tx7140\fs16\li2100 \
\b \
\fs28 openFile:\
\pard\b0\fi-1020\li3620 - (id)
\b openFile:
\b0 (Cstring)
\i filename
\b\i0 \
\fs16 \
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Calls
\b openFile:For:
\b0 using FileREADWROTE for the
\i operation
\i0 parameter. This, then, simply serves as a more common case wrapper around the preceeding method.\
\pard\tx7140\fs16\li2100 \
\b \
\fs28 closeFile
\b0 \
\pard\fi-1020\li3620 -
\b closeFile\
\fs16 \
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Closes the files, disposes of the instance values of the method and frees the object.\
\pard\tx7140\fs16\li2100 \
\b \
d224 10
d236 4
d291 19
d346 1
a346 1
\fs28 getPath\
d350 1
a350 1
\b getPath\
d354 1
a354 5
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Returns the path to the file, without including the file name itself. Note that it does include the final / in the pathname (e.g.
\f4 /usr/djb/super.eps
\f0 returns
\f4 /usr/djb/
\f0 ). The string that is generated must be disposed by the caller.\
d360 1
a360 1
\fs28 getPathname\
d362 8
a369 3
\pard\f1\b0\fi-1020\li3620 -
\f0 (Cstring)
\b getPathname\
d373 1
a373 1
\pard\tx3120\tx3620\tx4120\b0\fs28\li2620 Returns the full pathname to the file the object has open. This provides a new string which the recipient is responsible for disposing.\